﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Rob Ashton 2009
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@mvcex.com
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.UI.WebControls;
using System.Web;
using System.Web.Routing;
using System.Security.Principal;

namespace MvcEx.Controllers
{
    /// <summary>
    /// The base class for containing the actions that get bundled into a controller at runtime
    /// </summary>
    public partial class MvcExActionContainer
    {
        private MvcExController mParent;

        public MvcExActionContainer()
        {            
            var dummyController = new MvcExController();
            dummyController.RegisterContainer(this);
        }

        internal void Initialize(MvcExController parent)
        {
            mParent = parent;
        }

        public IActionInvoker ActionInvoker
        {
            get
            {
                return mParent.ActionInvoker;
            }
            set
            {
                mParent.ActionInvoker = value;
            }
        }

        // For now we'll do this generic method here cos I really need it
        // But I need to do this automatically too
        public void UpdateModel<T>(T model) where T : class
        {
            mParent.CallUpdateModel<T>(model);
        }
        public void UpdateModel<T>(T model, String prefix) where T : class
        {
            mParent.CallUpdateModel<T>(model, prefix);
        }

        public HttpContextBase HttpContext
        {
            get
            {
                return mParent.HttpContext;
            }
        }
        public ModelStateDictionary ModelState
        {
            get
            {
                return mParent.ModelState;
            }
        }

        public HttpRequestBase Request
        {
            get
            {
                return mParent.Request;
            }
        }
        public HttpResponseBase Response
        {
            get
            {
                return mParent.Response;
            }
        }
        public RouteData RouteData
        {
            get
            {
                return mParent.RouteData;
            }
        }
        public HttpServerUtilityBase Server
        {
            get
            {
                return mParent.Server;
            }
        }

        public HttpSessionStateBase Session
        {
            get
            {
                return mParent.Session;
            }
        }
        public ITempDataProvider TempDataProvider
        {
            get
            {
                return mParent.TempDataProvider;
            }
            set
            {
                mParent.TempDataProvider = value;
            }
        }
        public UrlHelper Url
        {
            get
            {
                return mParent.Url;
            }
            set
            {
                mParent.Url = value;
            }
        }
        public IPrincipal User
        {
            get
            {
                return mParent.User;
            }
        }

        public ControllerContext ControllerContext
        {
            get
            {
                return mParent.ControllerContext;
            }
            set
            {
                mParent.ControllerContext = value;
            }
        }
        public TempDataDictionary TempData
        {
            get
            {
                return mParent.TempData;
            }
            set
            {
                mParent.TempData = value;
            }
        }
        public bool ValidateRequest
        {
            get
            {
                return mParent.ValidateRequest;
            }
            set
            {
                mParent.ValidateRequest = value;
            }
        }
        public IDictionary<string, ValueProviderResult> ValueProvider
        {
            get
            {
                return mParent.ValueProvider;
            }
            set
            {
                mParent.ValueProvider = value;
            }
        }
        public ViewDataDictionary ViewData
        {
            get
            {
                return mParent.ViewData;
            }
            set
            {
                mParent.ViewData = value;
            }
        }
    }
}